package com.wiscamp.ninechapters.problems.enums;

/**
 * 数据操作枚举
 */
public enum Actions {
    NONE(0, "NONE"),
    CREATE(10, "CREATE"),
    UPDATE(20, "UPDATE"),
    DELETE(30, "DELETE");

    private final int value;

    private final String name;

    Actions(int value, String name) {
        this.value = value;
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public int getValue() {
        return value;
    }

    public static Actions valueOf(int value) {
        return switch (value) {
            case 10 -> Actions.CREATE;
            case 20 -> Actions.UPDATE;
            case 30 -> Actions.DELETE;
            default -> Actions.NONE;
        };
    }

    public static Actions nameOf(String name) {
        return switch (name.toUpperCase()) {
            case "CREATE" -> Actions.CREATE;
            case "UPDATE" -> Actions.UPDATE;
            case "DELETE" -> Actions.DELETE;
            default -> Actions.NONE;
        };
    }
}
